
local META = FindMetaTable( "Entity" )
assert( META )

function META:GetSyncVar( name, default )
	return syncvar.GetEntity( self, name, default )
end
function META:SetSyncVar( name, var, default )
	syncvar.SetEntity( self, name, var, default )
end

function META:SetBlinking( bool )
	if self:IsBlinking() == bool then return end
	return self:SetSyncVar( "blinking", bool )
end

function META:IsBlinking( )
	return self:GetSyncVar( "blinking", false )
end

-- Returns true if the melon is less than fHeight units above the ground. Entity:OnGround() doesn't appear to work.
function META:IsAboveGround( fHeight )
	local pos = self:GetPos()
	local tracedata = {}
	tracedata.start = pos
	tracedata.endpos = pos - ( vector_up * fHeight )
	tracedata.filter = self
	local trace = util.TraceLine(tracedata)
	return trace.Hit
end

function META:GetFlexByName( name )
	for i=0, self:GetFlexNum()-1 do
		if name == self:GetFlexName(i) then
			return i
		end
	end
	return -1
end